package com.gzw.dms.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gzw.dms.R;
import com.gzw.dms.bean.ShippingOrderInfo;

import java.util.List;

/**
 * Created by Administrator on 2016/8/16.
 */
public class QscxAdapter1 extends RecyclerView.Adapter{
    public static interface OnRecyclerViewListener {
        void onItemClick(int position);
        boolean onItemLongClick(int position);
    }
    private OnRecyclerViewListener onRecyclerViewListener;
    public void setOnRecyclerViewListener(OnRecyclerViewListener onRecyclerViewListener) {
        this.onRecyclerViewListener = onRecyclerViewListener;
    }
    private static final String TAG = AbonrmalAdapter.class.getSimpleName();
    private List<ShippingOrderInfo> list;
    public QscxAdapter1(List<ShippingOrderInfo> list) {
        this.list = list;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_qscx, null);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(lp);
        return new PersonViewHolder(view);
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
        PersonViewHolder holder = (PersonViewHolder) viewHolder;
        holder.position = i;
        ShippingOrderInfo shippingOrderInfo = list.get(i);
        holder.tv_shiping_order_num.setText("货运编号:"+shippingOrderInfo.getShiping_order_num());
        holder.tv_order_goid.setText("起运地:"+shippingOrderInfo.getSend_station());

        holder.tv_send_time.setText("起运时间:"+shippingOrderInfo.getSend_time());
        holder.tv_end_address.setText("收货客户地址:"+shippingOrderInfo.getEnd_mechanism());
        holder.tv_custom_name.setText("发货客户:"+shippingOrderInfo.getCustom_name());
        holder.tv_receipt_name.setText("终到位置:"+shippingOrderInfo.getEnd_address());

        if(shippingOrderInfo.getAging_day().equals("0")) {
            holder.tv_sx.setText("标准时效:"+ shippingOrderInfo.getAging_time() + "(当日)");
        }else if (shippingOrderInfo.getAging_day().equals("1")) {
            holder.tv_sx.setText("标准时效:" + shippingOrderInfo.getAging_time() + "(次日)");
        }else if (shippingOrderInfo.getAging_day().equals("2")) {
            holder.tv_sx.setText("标准时效:" + shippingOrderInfo.getAging_time() + "(隔日)");
        }

        String state =String.valueOf(shippingOrderInfo.getShipping_order_state());
//        if(state.equals("4")) {
//            holder.tv_sign_time.setText("签收时间:" + shippingOrderInfo.getSign_time());
//        }else if (state.equals("2")){
//            holder.tv_sign_time.setText("接单时间:" + shippingOrderInfo.getReceivetime());
//        }

        if(state.equals("0")){
            holder.tv_edit.setText("已发运");
            holder.tv_sign_time.setText("");
        }
        else if(state.equals("1")){
            holder.tv_edit.setText("已分配");
            holder.tv_sign_time.setText("");
        }
        else if(state.equals("2")){
            holder.tv_edit.setText("司机接单");
            holder.tv_sign_time.setText("接单时间:" + shippingOrderInfo.getReceivetime());
        }
        else if(state.equals("3")) {
            holder.tv_edit.setText("电子围栏签收");
        }else if(state.equals("4")) {
            holder.tv_edit.setText("实际签收");
            holder.tv_sign_time.setText("签收时间:" + shippingOrderInfo.getSign_time());
        }else if(state.equals("5")) {
            holder.tv_edit.setText("已返回");
            holder.tv_sign_time.setText("");
        }else if(state.equals("6")) {
            holder.tv_edit.setText("已收到");
            holder.tv_sign_time.setText("");
        }

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class PersonViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
        public View rootView;
        public TextView tv_order_goid;
        public TextView tv_shiping_order_num;
        public TextView tv_send_time;
        public TextView tv_end_address;
        public TextView tv_custom_name;
        public TextView tv_receipt_name;
        public TextView tv_sx;
        public TextView tv_sign_time;
        public TextView tv_edit;

        public int position;
        public PersonViewHolder(View itemView) {
            super(itemView);
            tv_order_goid = (TextView) itemView.findViewById(R.id.ic_shiping_order_goid).findViewById(R.id.tv_name);
            tv_shiping_order_num = (TextView) itemView.findViewById(R.id.ic_shiping_order_num).findViewById(R.id.tv_name);
            tv_send_time = (TextView) itemView.findViewById(R.id.ic_send_time).findViewById(R.id.tv_name);
            tv_end_address = (TextView) itemView.findViewById(R.id.ic_end_address).findViewById(R.id.tv_name);
            tv_custom_name = (TextView) itemView.findViewById(R.id.ic_custom_name).findViewById(R.id.tv_name);
            tv_receipt_name = (TextView) itemView.findViewById(R.id.ic_receipt_name).findViewById(R.id.tv_name);
            tv_sx = (TextView) itemView.findViewById(R.id.ic_sx).findViewById(R.id.tv_name);
            tv_sign_time = (TextView) itemView.findViewById(R.id.ic_sign_time).findViewById(R.id.tv_name);
            tv_edit = (TextView) itemView.findViewById(R.id.tv_edit);
            rootView = itemView.findViewById(R.id.ll);
            rootView.setOnClickListener(this);
            rootView.setOnLongClickListener(this);
        }
        @Override
        public void onClick(View v) {
            if (null != onRecyclerViewListener) {
                onRecyclerViewListener.onItemClick(position);
            }
        }
        @Override
        public boolean onLongClick(View v) {
            if (null != onRecyclerViewListener) {
                return onRecyclerViewListener.onItemLongClick(position);
            }
            return false;
        }
    }
}
